package com.lightboat.system.domain.dto;

import com.alibaba.fastjson2.JSONArray;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.extension.handlers.Fastjson2TypeHandler;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.deser.std.DateDeserializers;
import com.fasterxml.jackson.databind.ser.std.DateSerializer;
import com.lightboat.common.annotation.Excel;
import com.lightboat.common.core.domain.BaseEntity;
import com.lightboat.common.core.domain.bo.OrderProductBo;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.media.SchemaProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 订单对象 crm_order
 *
 * @author lightboat
 * @date 2025-08-14
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
@Schema(title = "订单Dto")
public class CrmOrderDto extends BaseEntity {
    private static final long serialVersionUID = 1L;

    /** 订单ID */
    @SchemaProperty(name = "订单ID")
    @TableId
    private Long orderId;

    /** 外部订单ID */
    @SchemaProperty(name = "外部订单ID")
    @Excel(name = "外部订单ID")
    private String externalOrderId;

    /** 商铺ID */
    @SchemaProperty(name = "商铺ID")
    @Excel(name = "商铺ID")
    private String storeId;

    /** 门店名称 */
    @SchemaProperty(name = "门店名称")
    @Excel(name = "门店名称")
    private String storeName;

    /** 客户ID */
    @SchemaProperty(name = "客户ID")
    @Excel(name = "客户ID")
    private Long customerId;

    /** 百度平台UID */
    @SchemaProperty(name = "百度平台UID")
    @Excel(name = "百度平台UID")
    private String uid;

    /** 订单编号 */
    @SchemaProperty(name = "订单编号")
    @Excel(name = "订单编号")
    private String orderNo;

    /** 状态（1置顶 2正常） */
    @SchemaProperty(name = "状态（1置顶 2正常）")
    @Excel(name = "状态", readConverterExp = "1=置顶,2=正常")
    private String topStatus;

    /** 置顶类型 */
    @SchemaProperty(name = "置顶类型")
    @Excel(name = "置顶类型")
    private String topType;

    /** 订单状态 */
    @SchemaProperty(name = "订单状态")
    @Excel(name = "订单状态")
    private Integer orderStatus;

    /** 支付方式 (1微信 2支付宝 3易收宝 4代收 5平台转定金) */
    @SchemaProperty(name = "支付方式 (1微信 2支付宝 3易收宝 4代收 5平台转定金)")
    @Excel(name = "支付方式 (1微信 2支付宝 3易收宝 4代收 5平台转定金)")
    private String paymentMethod;

    /** 支付方式名称 */
    @SchemaProperty(name = "支付方式名称")
    @Excel(name = "支付方式名称")
    private String paymentName;

    /** 商品信息（原信息） */
    @SchemaProperty(name = "商品信息（原信息）")
    @Excel(name = "商品信息", readConverterExp = "原=信息")
    @TableField(typeHandler = Fastjson2TypeHandler.class)
    private JSONArray products;

    /** 商品集合 */
    @SchemaProperty(name = "商品集合")
    @Excel(name = "商品集合")
    @TableField(typeHandler = Fastjson2TypeHandler.class)
    private List<OrderProductBo> productCollection;

    /** 商品图片 */
    @SchemaProperty(name = "商品图片")
    @Excel(name = "商品图片")
    private String productImg;

    /** 商品名称 */
    @SchemaProperty(name = "商品名称")
    @Excel(name = "商品名称")
    private String productName;

    /** 商品规格 */
    @SchemaProperty(name = "商品规格")
    @Excel(name = "商品规格")
    private String productSpec;

    /** 商品ID */
    @SchemaProperty(name = "商品ID")
    @Excel(name = "商品ID")
    private Long productId;

    /** 组合商品IDS */
    @SchemaProperty(name = "组合商品IDS")
    @Excel(name = "组合商品IDS")
    @TableField(typeHandler = Fastjson2TypeHandler.class)
    private List<String> groupProductIds;

    /** 商品价格 */
    @SchemaProperty(name = "商品价格")
    @Excel(name = "商品价格")
    private BigDecimal productPrice;

    /** 订单价格 */
    @SchemaProperty(name = "订单价格")
    @Excel(name = "订单价格")
    private BigDecimal orderPrice;

    /** 实付价格 */
    @SchemaProperty(name = "实付价格")
    @Excel(name = "实付价格")
    private BigDecimal actualPrice;

    /** 代收金额 */
    @SchemaProperty(name = "代收金额")
    @Excel(name = "代收金额")
    private BigDecimal codAmount;

    /** 总金额 */
    @SchemaProperty(name = "总金额")
    @Excel(name = "总金额")
    private BigDecimal totalAmount;

    /** 订单数量 */
    @SchemaProperty(name = "订单数量")
    @Excel(name = "订单数量")
    private Long orderQuantity;

    /** 收货人姓名 */
    @SchemaProperty(name = "收货人姓名")
    @Excel(name = "收货人姓名")
    private String receiverName;

    /** 收货人手机号 */
    @SchemaProperty(name = "收货人手机号")
    @Excel(name = "收货人手机号")
    private String receiverPhone;

    /** 收货人地址 */
    @SchemaProperty(name = "收货人地址")
    @Excel(name = "收货人地址")
    private String receiverAddress;

    /** 第几次下单 */
    @SchemaProperty(name = "第几次下单")
    @Excel(name = "第几次下单")
    private Long orderCount;

    /** 业务员ID */
    @SchemaProperty(name = "业务员ID")
    @Excel(name = "业务员ID")
    private Long salesmanId;

    /** 业务员姓名 */
    @SchemaProperty(name = "业务员姓名")
    @Excel(name = "业务员姓名")
    private String salesmanName;

    /** 业务员部门 */
    @SchemaProperty(name = "业务员部门")
    @Excel(name = "业务员部门")
    private String salesmanDept;

    /** 物流状态（0 待发货 1已签收 2拒绝签收 3已发货） */
    @SchemaProperty(name = "物流状态（0 待发货 1已签收 2拒绝签收 3已发货）")
    @Excel(name = "物流状态", readConverterExp = "0=待发货,1=已签收,2=拒绝签收,3=已发货")
    private String logisticsStatus;

    /** 物流签收时间 */
    @SchemaProperty(name = "物流签收时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonDeserialize(using = DateDeserializers.DateDeserializer.class)
    @JsonSerialize(using = DateSerializer.class)
    @Excel(name = "物流签收时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
    private Date logisticsSignTime;

    /** 物流编号 */
    @SchemaProperty(name = "物流编号")
    @Excel(name = "物流编号")
    private String logisticsNo;

    /** 包裹IDS */
    @SchemaProperty(name = "包裹IDS")
    @Excel(name = "包裹IDS")
    @TableField(typeHandler = Fastjson2TypeHandler.class)
    private JSONArray packageIds;

    /** 物流平台 */
    @SchemaProperty(name = "物流平台")
    @Excel(name = "物流平台")
    private String logisticsPlatform;

    /** 物流平台编码 */
    @Excel(name = "物流平台编码")
    @SchemaProperty(name = "物流平台编码")
    private String logisticsPlatformCode;

    /** 物流最新进展 */
    @SchemaProperty(name = "物流最新进展")
    @Excel(name = "物流最新进展")
    private String logisticsProgress;

    /** 类别 */
    @SchemaProperty(name = "类别")
    @Excel(name = "类别")
    @TableField(exist = false)
    private String category;

    /** 订单类别 */
    @SchemaProperty(name = "订单类别")
    @Excel(name = "订单类别")
    private String orderCategory;

    /** 是否添加微信(0 否 1是) */
    @SchemaProperty(name = "是否添加微信(0 否 1是)")
    @Excel(name = "是否添加微信(0 否 1是)")
    @TableField(exist = false)
    private Integer isAddWechat;

    /** 是子订单(0 否 1是) */
    @SchemaProperty(name = "是子订单(0 否 1是)")
    @Excel(name = "是子订单(0 否 1是)")
    private Integer isChildren;

    /** 是否大单（0否 1是） */
    @SchemaProperty(name = "是否大单（0否 1是）")
    @Excel(name = "是否大单", readConverterExp = "0=否,1=是")
    private Integer isBigOrder;

    /** 是否核销（0否 1是） */
    @SchemaProperty(name = "是否核销（0否 1是）")
    @Excel(name = "是否核销", readConverterExp = "0=否,1=是")
    private Integer isWriteOff;

    /** 是否多包裹（0否 1是） */
    @SchemaProperty(name = "是否多包裹（0否 1是）")
    @Excel(name = "是否多包裹", readConverterExp = "0=否,1=是")
    private Integer isMultiPackage;

    /** 是否补单（0否 1是） */
    @SchemaProperty(name = "是否补单（0否 1是）")
    @Excel(name = "是否补单", readConverterExp = "0=否,1=是")
    private Integer isReplenishOrder;

    /** 是否延期发货（0否 1是） */
    @SchemaProperty(name = "是否延期发货（0否 1是）")
    @Excel(name = "是否延期发货", readConverterExp = "0=否,1=是")
    private Integer isDelayedDelivery;

    /** 补单类型 */
    @SchemaProperty(name = "补单类型")
    @Excel(name = "补单类型")
    private String replenishOrderType;

    /** 下单时间 */
    @SchemaProperty(name = "下单时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonDeserialize(using = DateDeserializers.DateDeserializer.class)
    @JsonSerialize(using = DateSerializer.class)
    @Excel(name = "下单时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
    private Date orderTime;

    /** 置顶时间 */
    @SchemaProperty(name = "置顶时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonDeserialize(using = DateDeserializers.DateDeserializer.class)
    @JsonSerialize(using = DateSerializer.class)
    @Excel(name = "置顶时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
    private Date topTime;

    /** 平台 */
    @SchemaProperty(name = "平台")
    @Excel(name = "平台")
    private String platform;

    /** 关联订单ID */
    @SchemaProperty(name = "关联订单ID")
    @Excel(name = "关联订单ID")
    private String relatedOrderId;

    /** 订单类别（1系统 2复购） */
    @SchemaProperty(name = "订单类别（1系统 2复购）")
    @Excel(name = "订单类别", readConverterExp = "1=系统,2=复购")
    private Integer orderType;

    @SchemaProperty(name = "发货类型  1 系统发货 2 自主发货，都是我给你传的")
    private Integer shippingType;

    /** 订单渠道来源名称 */
    @SchemaProperty(name = "订单渠道来源名称")
    @Excel(name = "订单渠道来源名称")
    private String channelType;

    /** 订单渠道来源编码 */
    @SchemaProperty(name = "订单渠道来源编码")
    @Excel(name = "订单渠道来源编码")
    private String channelCode;

    /** 订单内容 */
    @SchemaProperty(name = "订单内容")
    @Excel(name = "订单内容")
    private String orderContent;

    /** 附件 */
    @SchemaProperty(name = "附件")
    @Excel(name = "附件")
    private String fileAttachment;

    /** 跟进备注 */
    @SchemaProperty(name = "跟进备注")
    @Excel(name = "跟进备注")
    private String followRemark;
    /** 跟进备注 */
    @SchemaProperty(name = "跟进备注1")
    @Excel(name = "跟进备注1")
    @TableField(exist = false)
    private String followRemark1;
    /** 跟进备注 */
    @SchemaProperty(name = "跟进备注2")
    @Excel(name = "跟进备注2")
    @TableField(exist = false)
    private String followRemark2;

    /** 订单备注 */
    @SchemaProperty(name = "订单备注")
    @Excel(name = "订单备注")
    private String orderRemark;

    /** 用户订单备注 */
    @SchemaProperty(name = "用户订单备注")
    @Excel(name = "用户订单备注")
    private String userRemark;

    /** 用户订单置顶备注 */
    @SchemaProperty(name = "用户订单置顶备注")
    @Excel(name = "用户订单置顶备注")
    private String topRemark;


    /** 子订单 */
    @TableField(exist = false)
    private List<CrmOrderDto> childrens = new ArrayList<>();
}
